package com.open.source.rabbit.provider.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author zhanglong and since on 2020/3/27 3:57 下午
 */
@Configuration
public class BindingConfig {
    @Resource
    private ExchangeConfig exchangeConfig;

    @Resource
    private QueueConfig queueConfig;

    @Bean
    Binding bindingDirect() {
        final DirectExchange directExchange = exchangeConfig.directExchange();
        return BindingBuilder.bind(queueConfig.directQueue()).to(directExchange).with("direct_routing_key");
    }

    @Bean
    Binding bindingExchangeA() {
        return BindingBuilder.bind(queueConfig.queueA()).to(exchangeConfig.fanoutExchange());
    }

    @Bean
    Binding bindingExchangeB() {
        return BindingBuilder.bind(queueConfig.queueB()).to(exchangeConfig.fanoutExchange());
    }

    @Bean
    Binding bindingExchangeC() {
        return BindingBuilder.bind(queueConfig.queueC()).to(exchangeConfig.fanoutExchange());
    }

    @Bean
    Binding bindingTopicFirst() {
        return BindingBuilder.bind(queueConfig.firstQueue()).to(exchangeConfig.topicExchange()).with("topic.man");
    }

    @Bean
    Binding bindingTopicSecond() {
        return BindingBuilder.bind(queueConfig.secondQueue()).to(exchangeConfig.topicExchange()).with("topic.*");
    }
}
